package com.order.api.controller;


import com.order.api.service.UsersService;
import com.order.api.target.Authorization;
import com.order.api.target.MethodLog;
import com.order.api.vo.BaseResult;
import com.order.api.vo.request.UserFindRequest;
import com.order.api.vo.request.UsersAddRequest;
import com.order.api.vo.request.UsersUpdateRequest;
import com.order.api.vo.response.UsersResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户模块")
@RestController
@RequestMapping(value = "/users")
public class UsersController {

    @Autowired
    private UsersService usersService;

    @ResponseBody
    @Authorization
    @ApiOperation("查询用户")
    @RequestMapping(value = "/find", method = RequestMethod.POST)
    @MethodLog(optType = "查询用户",systemModel = "用户模块")
    public BaseResult<UsersResponse> findUser(@RequestBody UserFindRequest request){
       return  BaseResult.success(usersService.findUser(request));
    }

    /*@Authorization
    @ResponseBody
    @ApiOperation("添加用户")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @MethodLog(optType = "添加用户",systemModel = "用户模块")
    public BaseResult<String> addUser(@RequestBody UsersAddRequest request){
        return BaseResult.judgeOperate(usersService.addUser(request));
    }*/

    @Authorization
    @ResponseBody
    @ApiOperation("修改用户")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @MethodLog(optType = "修改用户",systemModel = "用户模块")
    public BaseResult<String> updateUser(@RequestBody UsersUpdateRequest request){
        return BaseResult.judgeOperate(usersService.updateUser(request));

    }

    @Authorization
    @ResponseBody
    @ApiOperation("删除用户")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @MethodLog(optType = "删除用户",systemModel = "用户模块")
    public BaseResult<String> deleteUser(@RequestBody UserFindRequest request){
        return BaseResult.judgeOperate(usersService.deleteUser(request));
    }

}
